package edu.nf.identification.controller;

//import org.springframework.ai.chat.client.ResponseEntity;
import edu.nf.identification.pojo.IDCard;
import edu.nf.identification.service.AiModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/image")
public class ImageController {

    private final AiModelService aiModelService;

    public ImageController(AiModelService aiModelService) {
        this.aiModelService = aiModelService;
    }

    @PostMapping("/upload")
    public IDCard getCarCounts(@RequestParam("files") MultipartFile[] files) {
        List<byte[]> imagesData = new ArrayList<>();
        List<String> contentTypes = new ArrayList<>();

        for (MultipartFile file : files) {
            try {
                imagesData.add(file.getBytes());  // 缓存成 byte[]
                contentTypes.add(file.getContentType());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return aiModelService.defaultIDCard(imagesData, contentTypes);
    }
}